<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button class="btn">计算</button>
  <input type="text" id="num" placeholder="输入天数" value="40"/>
<script type="module">
  /* 
  1 1 2 3 5 8 ...
  f(n) = f(n-1) + f(n-2)
  */



  document.querySelector('button').onclick = function () {
    const num = document.getElementById('num').value*1
    // 创建worker
    const worker = new Worker('./10_worker.js', { 
      type: 'module' // 指定在分线程中可以通过es模块化语法引入其它JS模块
    })
    // 发送消息: 传递num
    worker.postMessage(num)
    // console.log('------')
    // 绑定接收消息的监听 接收result
    worker.onmessage = (event)=> {
      const result = event.data
      alert(result)
    }
  }
</script>
</body>
</html>